﻿using System;
using fastCSharp;

namespace diantou.web.management
{
    /// <summary>
    /// 问题调用
    /// </summary>
    [fastCSharp.code.cSharp.webCall(IsPool = true)]
    class problem : fastCSharp.code.cSharp.webCall.call<problem>
    {
        /// <summary>
        /// 是否支持压缩
        /// </summary>
        protected override bool isGZip { get { return false; } }
        /// <summary>
        /// 题目JSON
        /// </summary>
        /// <param name="problemId"></param>
        [fastCSharp.code.cSharp.webCall]
        public void Download(int problemId)
        {
            diantou.dataAccess.user user = web.pub.GetSessionUser(this);
            if (user.Permission == dataModel.user.permission.Admin)
            {
                diantou.dataAccess.tcpCall.problem.downloadZip(problemId, data =>
                {
                    if (data.Type == fastCSharp.net.returnValue.type.Success)
                    {
                        createResponse();
                        try
                        {
                            Response.SetZipContentType();
                            Response.ContentDisposition = ("attachment; filename=51nod_Problem_" + problemId.toString() + ".zip").getBytes();
                            response(data.Value);
                        }
                        finally { responseEnd(); }
                    }
                    else serverError500();
                });
            }
            else NotFound404();
        }
    }
}
